package com.edt.ichannel.api.service.impl;

import cc.edt.iceutils2.string.IceStringUtils;
import cc.edt.iceutils3.date.IceDateFormatUtils;
import com.edt.ichannel.api.entiy.local.RedPacketOrder;
import com.edt.ichannel.api.service.CityCodeService;
import com.edt.ichannel.api.service.EdtApiService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Service
public class CityCodeServiceImpl implements CityCodeService {
    @Resource
    private EdtApiService edtApiService;
    @Override
    public List<RedPacketOrder> transCityCodeForRedPackageOrder(List<RedPacketOrder> redPacketOrderList) {
        List<RedPacketOrder> redPacketOrderListNew = new ArrayList<>();
        String batchCode = IceDateFormatUtils.dateToString(new Date(),"yyyyMMddHHmmss");
        if(redPacketOrderList != null && !redPacketOrderList.isEmpty()){
            for (RedPacketOrder redPacketOrder : redPacketOrderList) {
                redPacketOrder.setBatchCode(batchCode);
                String cityCode = edtApiService.getCityCodeByCode(redPacketOrder.getCityCode());
                if(IceStringUtils.isNotBlank(cityCode)){
                    redPacketOrder.setCityCode(cityCode);
                    redPacketOrderListNew.add(redPacketOrder);
                }

            }
        }
        return redPacketOrderListNew;
    }
}
